﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace canyinguanlixitong 

{
    public partial class frmupdatesplei : Form
    {
        public frmupdatesplei()
        {
            InitializeComponent();
        }
        public int stuo;
        string strconn = "Data Source=.;Initial Catalog=Supermarket management system;Integrated Security=True";
        private void frmupdatesplei_Load(object sender, EventArgs e)
        {
            dzh();
        }
        public void dzh()
        {
            SqlConnection conn = new SqlConnection(strconn);
            conn.Open();
            string sql = @"SELECT   [Commodity type].slLei, commodity.spID, commodity.spName, commodity.spJia
FROM      commodity INNER JOIN
                [Commodity type] ON commodity.spLei = [Commodity type].SlId WHERE commodity.spID='"+stuo+"'";
            SqlCommand cmd = new SqlCommand(sql,conn);
           SqlDataReader reader=cmd.ExecuteReader();
           if (reader.Read())
           {
               textBox1.Text = reader["spID"].ToString();
               textBox2.Text = reader["spName"].ToString();
               textBox3.Text = reader["spJia"].ToString();
               textBox4.Text = reader["slLei"].ToString();
              
           }
        }


        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
              SqlConnection conn = new SqlConnection(strconn);
            conn.Open();
            int bianhao = Convert.ToInt32(this.textBox1.Text);
            string dj = this.textBox2.Text;
            
            string sql = "update commodity set spID='" + bianhao + "',spName='" + dj + "' where spID='" + stuo + "'";
            SqlCommand cmd = new SqlCommand(sql,conn);
            int i=cmd.ExecuteNonQuery();
            if (i>0)
            {
                MessageBox.Show("修改成功");
            }
            else
            {
                MessageBox.Show("修改失败");
            }
            conn.Close();
        }  
        }
    }

